import socket


# 创建实例
client = socket.socket()
# 设置地址和端口
ip_port = ("127.0.0.1", 8881)
# 进行连接
client.connect(ip_port)
# 接收连接成功的消息
data = client.recv(1024)
print(data.decode())

# 接收数据
while True:
    msg_input = input("请输入发送的消息：")
    client.send(msg_input.encode())
    print('send input msg success')

    if msg_input == 'exit':
        break

    # 接收第一个消息，即自己发送的消息
    print('prepare to receive the first msg')
    data = client.recv(1024)
    print(data.decode())
    # 接收第二个消息，一个随机数
    print('prepare to receive the second msg')
    data = client.recv(1024)
    print(data.decode())

# 对应server的打印结果
# 连接成功!
# 请输入发送的消息：cpu-90%
# send input msg success
# prepare to receive the first msg
# cpu-90%
# prepare to receive the second msg
# 922
# 请输入发送的消息：memory-8G
# send input msg success
# prepare to receive the first msg
# memory-8G
# prepare to receive the second msg
# 49
# 请输入发送的消息：harddisk-1000G
# send input msg success
# prepare to receive the first msg
# harddisk-1000G
# prepare to receive the second msg
# 424
# 请输入发送的消息：display-4K
# send input msg success
# prepare to receive the first msg
# display-4K
# prepare to receive the second msg
# 44
# 请输入发送的消息：exit
# send input msg success
#
# Process finished with exit code 0


# 对应server_async的打印结果
# 准备连接...
# 请输入发送的消息：cpu-90%
# send input msg success
# prepare to receive the first msg
# cpu-90%
# prepare to receive the second msg
# 50
# 请输入发送的消息：memory-8G
# send input msg success
# prepare to receive the first msg
# memory-8G
# prepare to receive the second msg
# 63
# 请输入发送的消息：harddisk-16G
# send input msg success
# prepare to receive the first msg
# harddisk-16G
# prepare to receive the second msg
# 60
# 请输入发送的消息：localhost-127.0.0.1
# send input msg success
# prepare to receive the first msg
# localhost-127.0.0.1
# prepare to receive the second msg
# 85
# 请输入发送的消息：exit
# send input msg success
#
# Process finished with exit code 0